#ifndef UDPCOMMUNICATOR_H
#define UDPCOMMUNICATOR_H

#include <QUdpSocket>
#include <QHostAddress>
#include <QMap>
#include <QByteArray>
#include "datamodel.h"

class UdpCommunicator : public QObject {
    Q_OBJECT

public:
    explicit UdpCommunicator(QObject *parent = nullptr);
    ~UdpCommunicator();

    bool start(const QString& sendIp, int sendPort,
               const QString& receiveIp, int receivePort);
    void stop();

    // 推荐：添加「quint16端口 + const QByteArray&数据」的重载（与调用完全匹配）
    void sendData(quint16 port, const QByteArray& data);

signals:
    void dataReceived(const QByteArray& data, int port);

private slots:
    void onDataReceived();

private:
    QUdpSocket* m_udpSocket;
    QHostAddress m_sendAddress;
    QHostAddress m_receiveAddress;
    QString m_remoteIp;
};

#endif // UDPCOMMUNICATOR_H
